package Model;

import java.security.Key;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.SecretKeySpec;

public class Encryption 
{
	private String KEY;
	private Cipher cipher;
	
	public Encryption(String key)
	{
		try
		{
			KEY = key;
			
			// Create key and cipher
	        Key aesKey = new SecretKeySpec(KEY.getBytes(), "AES");
	        cipher = Cipher.getInstance("AES");
	        
	        // encrypt the text
	        cipher.init(Cipher.DECRYPT_MODE, aesKey);
		}
		catch(Exception e)
		{}
	}
	
	
	public byte[] decrypt(byte[] b) throws IllegalBlockSizeException, BadPaddingException
	{
		if (b == null || b.length == 0 || (b.length == 1 && b[0] == 1))
			return b; 
					
		return cipher.doFinal(b);
	}

}